#!/bin/bash
# Run freqmine benchmark

###SHELLPACK preamble freqmine-bench 0

ITERATIONS=12
TESTLIST=

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam	--min-threads	FREQMINE_MIN_THREADS
###SHELLPACK parseargParam	--max-threads	FREQMINE_MAX_THREADS
###SHELLPACK parseargParam	--iterations	FREQMINE_ITERATIONS
###SHELLPACK parseargParam	--size          FREQMINE_SIZE
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required freqmine-${VERSION}
###SHELLPACK init_complete

###SHELLPACK threads_large_stride_begin $FREQMINE_MIN_THREADS $FREQMINE_MAX_THREADS $FREQMINE_ITERATIONS
	for SIZE in $FREQMINE_SIZE; do
		echo "Running $SIZE workload";
		#
		# IN_FILE and MIN_SUP are the benchmark input parameters.
		# Calculate the input data based on size of the run.
		#  - webdocs_[N]: Database with collection of [N] web HTML documents.
		#  - kosarak_[N]: Database with [N] anonymized click streams from an online newspaper.
		#
		#  The actual files are plain text, and quite cryptic (provided by parsec-3.0).
		#
		# The MIN_SUP (minimum-support) parameter acts as an offset for where to start scanning
		# the parsed (in-mem) datafile. These values are based on parsec, yet slightly adjusted
		# to increase runtime on some the smaller workloads. Smaller values will increase runtime.
		#
		if [ $SIZE = "large" ]; then
			IN_FILE=$SHELLPACK_SOURCES/freqmine-${VERSION}-installed/inputs/webdocs_250k.dat
			MIN_SUP=11000
		elif [ $SIZE = "medium" ]; then
			IN_FILE=$SHELLPACK_SOURCES/freqmine-${VERSION}-installed/inputs/kosarak_990k.dat
			MIN_SUP=730
		else # small or default/bogus
			IN_FILE=$SHELLPACK_SOURCES/freqmine-${VERSION}-installed/inputs/kosarak_500k.dat
			MIN_SUP=390
		fi

		monitor_pre_hook $LOGDIR_RESULTS $NR_THREADS
		###SHELLPACK iteration_begin $FREQMINE_ITERATIONS
			echo Starting threads $NR_THREADS/$FREQMINE_MAX_THREADS iteration $ITERATION/$FREQMINE_ITERATIONS
			export OMP_NUM_THREADS=$NR_THREADS
			save_rc $SHELLPACK_SOURCES/freqmine-${VERSION}-installed/freqmine $IN_FILE $MIN_SUP 2>&1 | \
			    tee $LOGDIR_RESULTS/freqmine-${NR_THREADS}-${ITERATION}.log
			recover_rc
			if [ $? -ne 0 ]; then
			    die Failed to run freqmine
			fi
		###SHELLPACK iteration_end $ITERATIONS
		monitor_post_hook $LOGDIR_RESULTS $NR_THREADS
	done
###SHELLPACK threads_stride_end

exit $SHELLPACK_SUCCESS
